/// <reference path="../sage/sage.util.js" />
/// <reference path="../sage/sage.input.__.base.js" />
/// <reference path="../sage/sage.input.objectlocation.js" />
/// <reference path="../sage/sage.input.ZZ.singletons.js" />

var FourKillGameView_ObjectLocation = Base.extend({
    initialize: function initialize(host) {
        //this.geo = null;
        this.enabled = false;
        this.host = false;
        this._10 = util.radians(10);
        this.dataByObjectId = {};
    },
    isAvailable: function isAvailable() {
        return true;
    },
    enable: function enable() {
        if (!this.enabled && GlobalInputHandlers.ObjectLocation.isAvailable() && GlobalInputHandlers.ObjectLocation.enabled) {
            this.enabled = true;
            var self = this;
            GlobalInputHandlers.ObjectLocation.subscribe("FourKillGameView.ObjectLocation", self);
        }
    },
    disable: function disable() {
        if (this.enabled) {
            this.enabled = false;
            GlobalInputHandlers.ObjectLocation.unsubscribe("FourKillGameView.ObjectLocation");
        }
    },
    fireEvent: function fireEvent(eventName, data) {
        if (eventName == "objectlocation") {
            this.dataByObjectId[data.oid] = GeoCoordinates.newInstance(data.latitude, data.longitude);
            //this.geo = GeoCoordinates.newInstance(data.latitude, data.longitude);
            if (data.prevent) data.preventDefault();
        }
    },
    getLocation: function getLocation(id) {
        return this.dataByObjectId[id];
    },
    update: function update(context) { }
    /*,
    update: function update(context) {
        if (this.geo != null) {
            this.geo.updateLocation(context);
            var c = context.camera,
                l = this.geo.locationRelativeToCamera,
                p = l.placement,
                d = Math.abs(l.distance),
                a = p.angleFromBearing, 
                b1 = c.bearing,
                b2 = b1;
            if (d > 3 && !isNaN(a)) {

                var absD = Math.abs(l.distance);
                a += b1;
                while (a > util._360) a -= util._360;
                c.normalizeBearingToAngle(a, this._10);
                b2 = c.bearing;
                var diff = Math.abs(b2 - a);

                if (diff < this._10 || (util._360 - diff) < this._10) {
                    if (absD > 0) {
                        var speed = .5;
                        if (absD > 1000) speed = 500;
                        else if (absD > 500) speed = 100;
                        else if (absD > 100) speed = 35;
                        else if (absD > 80) speed = 25;
                        else if (absD > 60) speed = 18;
                        else if (absD > 20) speed = 12;
                        else if (absD > 10) speed = 6;
                        else if (absD > 5) speed = 2;
                        else if (absD > 2) speed = 1;

                        c.move(speed);
                    }
                }
            }
        }
    }*/
});
